﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using nanoCMS.Core.Concrete;
using nanoCMS.Core.Membership;
using nanoCMS.Core.Providers;

namespace nanoCMS.Core.Test.Providers
{
    [TestClass]
    public class UserProvider_Test
    {
        readonly WorldContext worldContext = new WorldContext();
        private UserProvider userProvider;
        private MessageProvider messageProvider;
        private LanguageProvider languageProvider;
        [TestInitialize]
        public void Init()
        {
            userProvider = worldContext.UserProvider;
        }

        [TestMethod]
        public void CreateUser()
        {
            String guid = Guid.NewGuid().ToString();
            User user;
            User dbUser;
            userProvider.CreateUser(guid, "bla", guid, "Goran", out user, false);
            userProvider.GetUser(user.UserID, out dbUser);
            Assert.AreEqual(guid, dbUser.Email);
        }


        [TestMethod]
        public void CreateUser_EmailIsInUse()
        {
            String guid = Guid.NewGuid().ToString(); 
            User user;
            userProvider.CreateUser(guid, "bla", guid, "Goran", out user, false);
            Assert.AreEqual(userProvider.CreateUser(guid, "bla", guid, "Goran", out user, false), MembershipReturn.EmailInUse);
        }

        [TestMethod]
        public void SendAnActivationEmail()
        {
            Settings.RequireMailAuthorisation = true;
            string email = "vlatka.janes@yahoo.com";
            string password = "123456789";
            string username = "vlatka260";

            messageProvider.Add("Core", "en", "Thank you for creating your account.\n\nPlease follow this link to activate:" +
                                                           "<br /><br /><a href='http://www.domain.com/ActivateUser.aspx?Id={$userID$}'> Click here to activate your account </a>" +
                                                           "<br /><br /><br />" +
                                                           "Your username:  {$username$}<br />" +
                                                           "Your password:  {$password$}<br />" +
                                                           "Registered Email:  {$email$}<br />");
            
            User user;
            Assert.AreEqual(userProvider.CreateUser(email, password, username, out user), MembershipReturn.Success);
        }

    }
}
